var mongoose = require('mongoose');
require('../model/order.model');
var orderModel = mongoose.model('Order');

module.exports={
    findOrdersByStatus:findOrdersByStatus,
    updateOrders:updateOrders
}

//mId merchant id
function findOrdersByStatus(mId,status,callBack){
    orderModel.find({'merchant':mId,'status':status},function(err,doc){
        callBack(err,doc);
    }).populate('customer').sort({'createTime':-1});
}

//_id:order id
function updateOrders(_id,status,callBack){
    orderModel.update({'_id':_id},{'status':status},function (err,doc) {
        callBack(err,doc);
    })
}